fix: terminal input and cleanup - #47
Conversation
Wails v3 serializes []byte parameters as base64 over JSON. The frontend was sending raw keystrokes which failed with "illegal base64 data".
- Remove raw ANSI buffer dump, log buffer size instead - Remove per-keystroke "got input" log from exec mux - Remove "past lock" breadcrumb log - Log session count instead of full session objects in ListSessions - Log only command and tty in StartSession instead of full opts/context
- Centralize host-process signal forwarding into a single Manager-level goroutine instead of one per terminal session. Prevents signal delivery contention with multiple terminals open. - Use RLock instead of Lock in ListSessions (read-only operation). - Remove unused cleanPTYOutput function and listenOnOut function.
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughBackend refactoring shifts terminal session lifecycle management from external cancel channels to context-based control, introduces manager-wide signal forwarding for tracked commands, and removes debug logging. Frontend adds Base64 encoding for keystroke data before transmission. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@backend/pkg/plugin/exec/controller.go`:
- Around line 120-122: The controller currently initializes
terminal.NewManager(...) inside runLocalMux and assigns c.terminalManager there,
causing unsynchronized reads (nil/datarace) from methods like CreateSession,
ListSessions, GetSession, AttachSession, DetachSession, WriteSession,
CloseSession, and ResizeSession; instead, call terminal.NewManager(c.ctx,
c.logger) in ServiceStartup, assign the resulting manager to c.terminalManager
before spawning the goroutine, and pass the returned inMux, outMux, resizeMux
into runLocalMux as parameters so runLocalMux uses those channels but does not
perform the manager assignment (move creation/assignment out of
controller.runLocalMux into ServiceStartup and change runLocalMux signature to
accept inMux, outMux, resizeMux).
In `@backend/pkg/terminal/manager.go`:
- Around line 35-36: The session contexts are rooted in context.Background() so
shutting down m.ctx doesn't cancel active PTYs; update the code that creates
each session (the spot that currently uses context.Background() — referenced
around the session/spawn logic and line creating the session context) to derive
from the manager context (use m.ctx or context.WithCancel(m.ctx)) instead of
context.Background(), ensuring forwardSignals() exiting on m.ctx.Done() will
cancel sessions and trigger handleSessionClose; also verify any goroutines that
run per-session accept that derived context and propagate it to the PTY
lifecycle and handleSessionClose invocation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 7dd2f5be-f43a-4708-abc5-2c81a17a00f5
📒 Files selected for processing (4)
backend/pkg/plugin/exec/controller.gobackend/pkg/terminal/manager.gobackend/pkg/terminal/manager_windows.goui/providers/BottomDrawer/containers/Terminal.tsx
- Move terminal.NewManager() from runLocalMux goroutine into ServiceStartup so c.terminalManager is initialized before any goroutine can access it. - Derive session contexts from m.ctx instead of context.Background() so manager shutdown cascades to all active PTY sessions.
Summary
WriteSession— Wails v3 serializes[]byteas base64 over JSON, but the frontend was sending raw keystrokes, causing every keystroke to fail withillegal base64 data at input byte 0cleanPTYOutputandlistenOnOutfunctionsTest plan
Summary by CodeRabbit